package ofmybatis.demo.dbConfig;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Primary
    @ConfigurationProperties("spring.datasource.druid.one")
    @Bean(value = "dataSourcePrimary")
    @Qualifier("dataSourcePrimary")
    public DataSource dataSource1(){
        return DruidDataSourceBuilder.create().build();
    }

    @ConfigurationProperties("spring.datasource.druid.two")
    @Bean(value = "dataSourceBack")
    @Qualifier("dataSourceBack")
    public DataSource dataSourceBack(){
        return DruidDataSourceBuilder.create().build();
    }

}
